package com.taptech.doufu.ui.viewholder.albums;

import android.content.Context;
import android.os.Handler;
import androidx.recyclerview.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.taptech.doufu.util.DensityUtil;
import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.MoreAlbumsActivity;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.bean.AlbumsBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.util.ImageManager;
import com.taptech.doufu.util.StartActivityUtil;

/**
 * Created by lsy on 2015/6/29.
 */

public class MoreNovelCategoryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener
{
    Context mContext;
    /**
     * UI控件
     */
    protected View mSubjectLayout;
    protected SimpleDraweeView mSubjectImageView;
    protected TextView mSubjectDescribtionView;
    private int darkColorTitle = 0xff898989;
    /**
     * 数据
     */
    protected AlbumsBean contentBean;
    protected Handler mHandler;
    protected int mPositon;

    public MoreNovelCategoryViewHolder(View itemView, Context context)
    {

        super(itemView);
        mContext = context;
        mSubjectLayout = (View) itemView.findViewById(R.id.subject_layout);
        mSubjectImageView = (SimpleDraweeView) itemView.findViewById(R.id.subject_imageview);
        ViewGroup.LayoutParams params = mSubjectImageView.getLayoutParams();
        params.width = DensityUtil.dip2px(mContext, 100);
        params.height = DensityUtil.dip2px(mContext, 100);
        mSubjectImageView.setLayoutParams(params);
        mSubjectDescribtionView = (TextView) itemView.findViewById(R.id.subject_describtion);
        mSubjectLayout.setOnClickListener(this);
        changeModel();
    }


    public void setChildContent(AlbumsBean bean, int position)
    {

        contentBean = bean;
        if (bean == null)
        {
            return;
        }
        mPositon = position;

        if (bean.getIcon() != null || bean.getCover() != null)
        {
//            mSubjectImageView.setBackgroundColor(Color.WHITE);
            ImageManager.loadImage(mSubjectImageView, MoreAlbumsActivity.type == MoreAlbumsActivity.HOT_ALBMUS ? bean.getIcon() : bean.getCover(), MoreAlbumsActivity.type == MoreAlbumsActivity.HOT_ALBMUS ? 2.0f : 1.0f);
            // ImageManager.displayImage(mSubjectImageView,bean.getIcon());
        }
        if ((bean.getName() != null)&&(bean.getNum()!=null))
        {
            if(!"0".equals(bean.getNum())){
                int strLength = bean.getName().length() + bean.getNum().length() + 4;
                SpannableString styledText = new SpannableString(bean.getName()+"\n"+bean.getNum()+"部作品");
                styledText.setSpan(new TextAppearanceSpan(mContext, R.style.textview_one), 0, bean.getName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                styledText.setSpan(new TextAppearanceSpan(mContext, R.style.textview_two), bean.getName().length(), strLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                mSubjectDescribtionView.setText(styledText, TextView.BufferType.SPANNABLE);
            }else{
                if(WeMediaApplication.getInstance().isDayNightMode_Night){
                    mSubjectDescribtionView.setTextColor(WeMediaApplication.getInstance().getResources().getColor(R.color.text_dark));
                }else {
                    mSubjectDescribtionView.setTextColor(0xFF303030);
                }
                mSubjectDescribtionView.setText(bean.getName());
            }
        }

    }

    public void setHandler(Handler handler)
    {
        mHandler = handler;
    }

    @Override
    public void onClick(View view)
    {

        switch (view.getId())
        {
            case R.id.subject_layout:
                StartActivityUtil.albumsOnclick(mContext, contentBean);
                break;
        }
    }

    @Override
    public boolean onLongClick(View view)
    {

        return true;
    }

 private void changeModel(){
     if(WeMediaApplication.getInstance().isDayNightMode_Night){
         mSubjectImageView.setAlpha(Constant.imagViewAlpha);
     }else {
         mSubjectImageView.setAlpha(1.0f);

     }
 }
}
